package com.stormdzh.study.controller;

import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.stormdzh.study.service.TbUsersService;
import com.stormdzh.study.service.model.TbUsers;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Arrays;
import java.util.List;

//测试数据库连接，回显数据demo：http://www.noobyard.com/article/p-qwedkvgv-hx.html
//根据数据，自动生成java 数据库表的实体类对象：http://jboot.com.cn/docs/start.html

@RequestMapping("/")
public class IndexController extends JbootController {

    @Inject
    TbUsersService tbUsersService;

    //hello world
    public void index() {
        renderText("Hello World Jboot");
    }


    //普通查询
    public void dbtest(){
        List<Record> records = Db.find("select * from tb_users");
        renderText(Arrays.toString(records.toArray()));
    }

    //生成数据库代码查询
    public void getuser(){
        List<TbUsers> users = tbUsersService.findAll();
        users=tbUsersService.paginate(1,1).getList();
        renderJson(users);

    }

    public  void getuser2(){
//        String keyword = "1";
//        Integer csStatType = 1;
//        Kv queryData = Kv.by("csStatType", csStatType).set("keyword",keyword);
        List<Record> recordList = Db.template("tb_users.getUsers").find();
        renderJson(recordList);
    }

}
